/*******************************************\
|					    |
| Header file that displays the Easy Level  |
| high scores 				    |
|					    |
| Call highscore_easy () with int score.    |
|					    |
| 					    |
\*******************************************/

#include <ncurses.h>
#include <stdio.h>
#include <string.h> 
#include <stdlib.h>

// FILE *fp;	/* Pointer to highscore_list_e.txt */

/* Inserts the new highscore and prints the high score list from ./highscore_list_e.txt */
int easy_score(char name[], int score)
{
	int x, y, i;		/* column and row */
	char buffer[20];	/* Array to read file lines into */

	clear();

	/* Prints header for high score screen. */
	mvprintw(2, (getmaxx(stdscr)/2) - 5, "HIGH SCORES");
	mvprintw(3, (getmaxx(stdscr)/2) - 5, "LEVEL: EASY");
	refresh();

	fp = fopen("./highscore_list_e.txt", "a");	/* Opens highscore list to append. */

	fprintf(fp, "%s\t\t%6d", name, score);		/* Appends new name and score to file. */

	fclose(fp);
	
	system("./enter_easy.sh");		/* Runs script that organizes highscores by score. */

	x = 1;
	y = 5;

	fp = fopen("./highscore_list_e.txt", "r");	/* Reopens file for reading. */

	while(fgets(buffer, 15, fp) != NULL)	/* Reads and prints the txt file line by line. */
	{
		y++;
		mvprintw(y, x, "%s", buffer);
	}	

	fclose(fp);

	mvprintw(23, 1, "Press q to continue.");
	refresh();
	
	nodelay(stdscr, FALSE);
	
	while((i = getch()) != 'q')
	{
		mvprintw(25, 3, "********************");
		refresh();
	/*	if(i == 'q')
		{	
			mvprintw(26, 3, "TESTING*****");
			refresh();
			return;
		} */
	}

	return;
}

/* Allows user to enter initials for high score. */
/* Accepts every other input. Solution pending.  */
int highscore_easy(int score)
{
	char name[3];		/* Array to store user initials. */
	clear();

	mvprintw(4, 7, "Your score is %i", score);
	mvprintw(5, 7, "Please enter your initials (xxx): ");	/* asks for user name, 3 characters long */
	refresh();
	getstr(name);		/* User enters initials */
	
	easy_score(name, score);	/* Sends new name and score to update the high score list. */

	
	return;
}

/*
main()
{
	int score = 1000;
        initscr();
    	cbreak();
        keypad(stdscr, TRUE);
	echo();
	while(1)
		highscore_easy(score);

	endwin();

	return;
} */
